package com.neusoft.chenhanhua.d0912;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.io.File;

import javax.swing.JPanel;

public class Chess {
	private String name;//名称
	private int x;//x的坐标
	private int y;//y的坐标
	private Point p;//用于计算x和y
	private int size=30;//棋子大小
	private int space=40;//间隔
	private int margin=20;//边距
	private int player;//阵营
	private String folder="pic"+File.separator;
	private String suffix=".png";
	
	public void draw(Graphics g, JPanel panel) {//pic/"+name[j]+zhenying+".png   folder + name + player + suffix
		Image img = Toolkit.getDefaultToolkit().getImage(folder + name + player + suffix);
		System.out.println(img);
		g.drawImage(img, x, y, size, size, panel);
	}
	public Chess(String name, Point p, int player) {
		this.name = name;
		setP(p);
		this.player = player;
	}
	
	public void calXY() {
		System.out.println(11);
		x = margin - size / 2 + space * (p.x - 1);
		y = margin - size / 2 + space * (p.y - 1);
	}
	
	/**
	 * 反转坐标
	 */
	public void reserve() {
		p.x = 10 - p.x;
		p.y = 11 - p.y;
		setP(p);
	}
	
	//在类中属性一般是不允许直接在其它类中直接使用的，建议使用get和set方法来设置获取属性值
		public void setName(String name) {
			this.name = name;
		}
		
		public void setP(Point p) {
			this.p = p;
			calXY();
		}
		
		public void setPlayer(int player) {
			this.player = player;
		}
	

}
